$( document ).ready(function() {
  $('.right-menu').css('top', $(".WordSection1").offset().top+'px');
  $('#navigationbody').css('position', 'fixed');
});

$(window).scroll(function(event){
	var rmenu_top = $(".WordSection1").offset().top - $(this).scrollTop();
	var rmenu_right = $(window).width() - ($(".SVjournal").position().left + $(".SVjournal").outerWidth() + 110) - $(".right-menu").width() + $(this).scrollLeft();
	if(rmenu_top<10) rmenu_top = 10;
	if(rmenu_right>30) rmenu_right = 30;
	$('.right-menu').css('top', rmenu_top+'px');
	$('.right-menu').css('right', rmenu_right+'px');

	var lmenu = $('#navigation').offset().top - $(this).scrollTop();
	if (lmenu<-10) lmenu = -10;
	$('#navigationbody').css('top', lmenu+'px');
});

$(window).resize(function(event){
	var rmenu_right = $(window).width() - ($(".SVjournal").position().left + $(".SVjournal").outerWidth() + 110) - $(".right-menu").width() + $(this).scrollLeft();
	if(rmenu_right>30) rmenu_right = 30;
	$('.right-menu').css('right', rmenu_right+'px');
});

function showText()
{ 
	$('.tagcut').css('display', 'block');
	$('#contents').css('display', 'block');
	$('#OpenTextBtn').css('display','none');
	return false;
}

function showCite()
{ 
	var cit = $('#citation').css('display');
	
	$('#citation').css('display', ((cit=='block')?'none':'block'));
	return false;
}

 // Get the modal
var modal = document.getElementById('myModal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
for(i=1; i<99; i++)
{
	var img = document.getElementById('Рисунок '+i);
	var modalImg = document.getElementById("img01");
	var captionText = document.getElementById("caption");
	if (img!=null) 
	{
		var css = '#Рисунок\\ ' + i +
				'{ border-radius: 5px; cursor: pointer; transition: 0.3s; } ' +
				'#Рисунок\\ ' + i + ':hover {opacity: 0.7;}';
		var style = document.createElement('style');

		if (style.styleSheet) {
			style.styleSheet.cssText = css;
		} else {
			style.appendChild(document.createTextNode(css));
		}

		document.getElementsByTagName('head')[0].appendChild(style);
		
		img.onclick = function(){
			modal.style.display = "block";
			modalImg.src = this.src;
			//captionText.innerHTML = this.alt;
			
			imageWidth = this.width, //need the raw width due to a jquery bug that affects chrome
			imageHeight = this.height, //need the raw height due to a jquery bug that affects chrome
			maxWidth = $(window).width(),
			maxHeight = $(window).height(),
			widthRatio = maxWidth / imageWidth,
			heightRatio = maxHeight / imageHeight;

			var ratio = 0.95 * ((widthRatio>heightRatio)?heightRatio:widthRatio);			
			
			$("#img01").css("width", imageWidth * ratio+"px")
			$("#img01").css("height", imageHeight * ratio+"px");
			
			//console.log(ratio);
		}
	}
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
} 